//
//  HCStoreRecommendView.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/2/8.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCStoreRecommendView.h"

#import "HCStoreReTableViewCell.h"

#import "HCFindStoreRecModel.h"

@interface HCStoreRecommendView () <UITableViewDelegate,UITableViewDataSource> {
    UITableView *tableView_;
    HCFindStoreRecModel *recModel;
}

@end

@implementation HCStoreRecommendView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self initializeSubView:frame];
    }
    return self;
}

-(void)initializeSubView:(CGRect)frame {
    tableView_ = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
    tableView_.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView_.delegate = self;
    tableView_.dataSource = self;
    tableView_.rowHeight = YBKAdaptiveW(230);
    tableView_.showsVerticalScrollIndicator = NO;
    tableView_.backgroundColor = YBKRGBCOLOR(241, 241, 241, 1);
    [self addSubview:tableView_];
    
    [tableView_ registerNib:[UINib nibWithNibName:@"HCStoreReTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"storere"];
//    MJRefreshNormalHeader *ad = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        NSLog(@"刷新");
//    }];
////    ad.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
//    tableView_.mj_header = ad;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (recModel) {
        return recModel.f_shop_activity.count;
    }else{
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HCStoreReTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"storere" forIndexPath:indexPath];
    if (recModel) {
        
        HCFindStoreRecData *data = recModel.f_shop_activity[indexPath.row];
        
        cell.model = data;
    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if ([self.delegate respondsToSelector:@selector(storeRecommendUrl:)]&&self.delegate) {
        HCFindStoreRecData *data = recModel.f_shop_activity[indexPath.row];
        [self.delegate storeRecommendUrl:data.url];
    }
    
}

-(void)setModel:(id)model {
    recModel = (HCFindStoreRecModel *)model;
    [tableView_ reloadData];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
